package com.cs.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cs.es.ProdEs;
import com.cs.service.SearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "前台搜索的接口")
@RestController
public class SearchController {
    @Autowired
    private SearchService searchService;

    /**
     * 通过分组标签的id查询商品
     * @return
     */
    @ApiOperation(value ="通过分组标签的id查询商品" )
    @GetMapping("/prod/prodListByTagId")
    public ResponseEntity<Page<ProdEs>> prodListByTagId(@RequestParam(required = false,defaultValue = "0") Integer page, Integer size, Long tagId){
        Page<ProdEs> prodEsPage = searchService.prodListByTagId(page, size, tagId);
        return ResponseEntity.ok(prodEsPage);
    }

    /**
     * 通过关键字查询商品
     */
    @GetMapping("/search/searchProdPage")
    @ApiOperation(value ="通过关键字查询商品" )
    public ResponseEntity<Page<ProdEs>> searchProdPage(@RequestParam(required = false,defaultValue = "0") Integer current ,Integer size,String prodName,Integer sort){
        Page<ProdEs> prodEsPage = searchService.searchProdPage(current, size, prodName, sort);
        return ResponseEntity.ok(prodEsPage);
    }



}
